<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--
  Created by IntelliJ IDEA.
  User: lxf
  Date: 2016/7/5
  Time: 14:15
  To change this template use File | Settings | File Templates.
--%>
<html>
<head>
    <title>地图</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=WVMhxB9xyPnirLQHwpNCrZ3B"></script>
    <style type="text/css">
        html {
            height: 100%
        }

        body {
            height: 100%;
            margin: 0px;
            padding: 0px
        }

        #baiduContainer {
            height: 500px;
            width: 1200px;
        }
    </style>
</head>
<body>
<div id="baiduContainer"></div>
<myScript>
    <script type="text/javascript">
        var map = new BMap.Map("baiduContainer");
        var point = new BMap.Point(104.06667, 30.66667);
        map.centerAndZoom(point, 15);
        var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
        var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
        var top_right_navigation = new BMap.NavigationControl({
            anchor: BMAP_ANCHOR_TOP_RIGHT,
            type: BMAP_NAVIGATION_CONTROL_ZOOM
        });
        /*  BMAP_NAVIGATION_CONTROL_SMALL  //默认平移+缩放
         BMAP_NAVIGATION_CONTROL_PAN //平移
         BMAP_NAVIGATION_CONTROL_ZOOM //缩放 */
        var mapType1 = new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP, BMAP_HYBRID_MAP]});
        var mapType2 = new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT});
        var overView = new BMap.OverviewMapControl();
        var overViewOpen = new BMap.OverviewMapControl({isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT});
        var locationControl = new BMap.NavigationControl({
            anchor: BMAP_ANCHOR_TOP_LEFT,
            type: BMAP_NAVIGATION_CONTROL_LARGE,
            enableGeolocation: true
        });

        map.addControl(top_left_control);
        //        map.addControl(top_left_navigation);
        //        map.addControl(top_right_navigation);
        map.addControl(locationControl);
        //        map.addControl(mapType1);          //2D图，卫星图
        //        map.addControl(mapType2);          //左上角，默认地图控件
        //        map.setCurrentCity("成都");        //由于有3D图，需要设置城市哦
        //        map.addControl(overView);          //添加默认缩略地图控件
        //        map.addControl(overViewOpen);      //右下角，打开

        // 添加定位控件
        var geolocationControl = new BMap.GeolocationControl();
        geolocationControl.addEventListener("locationSuccess", function (e) {
            // 定位成功
            var address = '';
            address += e.addressComponent.province;
            address += e.addressComponent.city;
            address += e.addressComponent.district;
            address += e.addressComponent.street;
            address += e.addressComponent.streetNumber;
            alert("当前定位地址为：" + address);
        });
        geolocationControl.addEventListener("locationError", function (e) {
            // 定位失败
            alert(e.message);
        });
        map.addControl(geolocationControl);
    </script>
</myScript>
</body>
</html>
